package com.yyhh.helpcall.utils;


import java.io.File;
import java.io.FileInputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.ArrayList;

public class FileUtil {

    public static String getFileMD5(File file) {
        MessageDigest digest = null;
        FileInputStream in = null;
        byte buffer[] = new byte[1024];
        int len;
        try {
            digest = MessageDigest.getInstance("MD5");
            in = new FileInputStream(file);
            while ((len = in.read(buffer, 0, 1024)) != -1) {
                digest.update(buffer, 0, len);
            }
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return bytesToHexString(digest.digest());
    }

    public static String bytesToHexString(byte[] src) {
        BigInteger bigInt = new BigInteger(1, src);//1代表绝对值
        return bigInt.toString(16);//转换为16进制
    }


    public static String findFilePathExist(ArrayList<String> paths){
        for(int i = 0; i < paths.size(); i ++){
            String path = paths.get(i);
            File file = new File(ScanRecordUtils.SDCARD +  path);
            if(file.exists()){
                return path;
            }
        }
        return null;
    }
}
